#ifndef _BACKDROP_EDITOR_H_
#define _BACKDROP_EDITOR_H_

#include "input/mouse.h"
#include "input/keyboard.h"

namespace backdrop
{
class Backdrop;
class BackdropEditor;


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// BackdropBrush
//

class BackdropBrush
{
public:
	BackdropBrush(BackdropEditor* pEditor, const std::string& Name) : m_pEditor(pEditor), m_Name(Name) {}
	virtual ~BackdropBrush() { Clear(); }

	virtual void		Clear() {}
	virtual void		Tick(float dt) = 0;
	virtual void		Render() = 0;

	virtual void		FollowMouse(const math::Vec2& Pos) = 0;
	virtual void		Place() = 0;
	virtual void		Rotate(const int& Dir = 0) {}

	void				SetType(const std::string& Type) { m_Type = Type; }
	const std::string&	GetName() { return m_Name; }
	const std::string&	GetType() { return m_Type; }

protected:
	BackdropEditor*		m_pEditor;
	math::Vec2			m_Pos;
	std::string			m_Name;
	std::string			m_Type;
};


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// BackdropEditor
//

class BackdropEditor
{
public:
	enum EDITOR_MODE {
		MODE_DEFAULT = 0,
		MODE_BACKGROUND,
		MODE_DECAL,
		MODE_TRANSIENT,
		MODE_USER = 127,
	};

	BackdropEditor(Backdrop* pBackdrop);
	virtual ~BackdropEditor();

	virtual void	Clear();
	virtual void	Tick(float dt);
	virtual void	Render();

	virtual void	MouseButtonDown(input::Mouse::BUTTON_STATE* pKey, const math::Vec2& Pos) {}
	virtual void	MouseButtonReleased(input::Mouse::BUTTON_STATE* pKey, const math::Vec2& Pos) {}
	virtual void	MouseButtonPressed(input::Mouse::BUTTON_STATE* pKey, const math::Vec2& Pos);
	virtual void	MouseWheelMove(int WheelInfo, const math::Vec2& Pos);
	virtual void	MouseMove(const math::Vec2& From, const math::Vec2& To);
	virtual void	KeyPressed(input::Keyboard::KEY* pKey);

	virtual void	SetDecalBrush(const std::string& Name, const std::string& Type = "");
	virtual void	SetTransientBrush(const std::string& Name, int Layer = -1);

	void			AddStatusMsg(const std::string& Message);
	Backdrop*		GetBackdrop() { return m_pBackdrop; }
	void			SetDecalBrushType(const std::string& Type);

	virtual math::Vec2	GetOffset() const { return math::Vec2(0.0f, 0.0f); }

protected:
	virtual void	TransientFunction() {}
	virtual void	BackgroundFunction() = 0;
	virtual void	DecalsFunction() = 0;
	virtual void	SaveFunction(bool QuickSave = false) = 0;
	virtual void	LoadFunction() = 0;
	virtual void	LoadNextFunction(bool bNext = true) = 0;
	virtual void	ExitFunction() = 0;
	virtual void	ClearAllFunction() = 0;

	virtual bool	CopyBrushSpecial(const math::Vec2& Pos, bool bBackground) { return false; }
	virtual bool	DeleteSpecial(const math::Vec2& Pos, bool bBackground) { return false; }
	virtual void	RefreshAltText() {}

private:
	virtual void	RenderInstructions();
	virtual void	RenderStatus();
	virtual void	RenderFileName();
	virtual void	RenderGridLines();

protected:
	Backdrop*		m_pBackdrop;
	BackdropBrush*	m_pBrush;
	EDITOR_MODE		m_EditMode;
	std::string		m_Instructions;
	std::string		m_AltInstructions;
	std::string		m_BrushType;
	math::Vec2		m_InstructOffset;
	math::Vec2		m_StatusOffset;

private:
	const static int	STATUS_LINES = 10;

	std::string		m_StatusMsg[STATUS_LINES];
	int				m_CurStatus;
};

} // namespace backdrop

#endif // _BACKDROP_EDITOR_H_
